import java.util.Random;
import java.util.Scanner;

public class Main
{
    public static int firstNumber = 21;
    public static int inputNumberPlayer = 0;
    public static int inputNumberComputer = 0;
    public static boolean randomAnswer = true;

    public static void main(String[] args){
        Random r = new Random();
        boolean random = r.nextBoolean();
        whoFirstGoing(random);

        for(int hod=0;firstNumber!=0;hod++){
            whoGoing();

            if(randomAnswer==true){
                inputNumberPlayer = Player.player();
                Game.game(inputNumberPlayer);
                randomAnswer=false;
            }
            else{
                inputNumberComputer = Computer.computer();
                Game.game(inputNumberComputer);
                randomAnswer=true;
            }
        }
        winner();
    }

    public static void winner(){
        if(randomAnswer==true){
            System.out.println("\n"+"WINNER PLAYER ");
        }
        else{
            System.out.println("\n"+"WINNER COMPUTER ");
        }
    }

    public static void whoFirstGoing(boolean random){

        if(random==true){
            randomAnswer =true;
        }
        else{
            randomAnswer = false;
        }
    }

    public static void whoGoing(){
        String text = text();
        System.out.println("\n"+"GOING " + text);
        System.out.println("LAST NUMBER " + firstNumber);
    }

    public static String text(){
    String text;
    if(randomAnswer==true){
        text = "PLAYER";
    }
    else {
        text = "COMPUTER";
    }
    return text;
}

    public static class Player{

        public static int playerNumber;
        public static int player(){
        printPlayer();
        scannerPlayer();
        return playerNumber;
        }

        public static void printPlayer(){
            System.out.println("ENTER NUMBER 1-5");
        }

        public static void scannerPlayer(){
            Scanner scannerPlayer = new Scanner(System.in);
            int number = scannerPlayer.nextInt();
            playerTry(number);
        }

        public static void playerTry(int number){
            if(number >= 1 & number <= 5 & firstNumber>=number)
            {
                playerNumber = number;
            }
            else
            {
                System.out.println("BAD NUMBER");
                scannerPlayer();
            }
        }
    }

    public static class Computer{

        public static int computer(){
            int intellect=intellect();
            printComputer(intellect);
            return intellect;
        }

        public static void printComputer(int intellect){
            System.out.println("COMPUTER ENTER NUMBER: " + intellect);
        }

        public static int intellect(){
            Random r = new Random();
            int random = r.nextInt(5)+1;
            int number = random;
            switch (firstNumber){
                case(21): number = 2; return number;
                case(20): number = 1; return number;
                case(14): number = 1; return number;
                case(8): number = 1; return number;
                case(6): number = 5; return number;
                case(5): number = 4; return number;
                case(4): number = 3; return number;
                case(3): number = 2; return number;
                case(2): number = 1; return number;
                case(1): number = 1; return number;
            }return number;
        }
    }

    public static class Game{

        public static void game(int input) {
            firstNumber = firstNumber - input;
        }
    }
}
